
package com.ami.kvm.jviewer.gui;

import java.awt.AWTException;
import java.awt.AlphaComposite;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputAdapter;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.hid.KeyProcessor;
import com.ami.kvm.jviewer.hid.USBKeyProcessorEnglish;
import com.ami.kvm.jviewer.hid.USBKeyboardRep;
import com.ami.kvm.jviewer.hid.USBMouseRep;
import com.ami.kvm.jviewer.kvmpkts.KVMClient;
import com.ami.kvm.jviewer.kvmpkts.Mousecaliberation;

public class JViewerView extends JComponent {
	private static final long serialVersionUID = 1L;
	public static final int DEFAULT_VIEW_WIDTH = 1600;
	public static final int DEFAULT_VIEW_HEIGHT = 1200;
	public static float MOUSE_ACCELERATION = 2.0F;
	public static int ACCEL_THRESHOLD = 4;
	public static boolean firsttime = true;
	public static float RemainingX = 0.0F;
	public static float RemainingY = 0.0F;
	public static boolean Lost_focus_flag = false;
	public static int Mouse_X = 0;
	public static int Mouse_Y = 0;
	private int m_act_width;
	private int m_act_height;
	private short currentWidth;
	private short currentHeight;
	private int m_width;
	private int m_height;
	public RCMouseListener mouseListener;
	public RCKeyListener keyListener;
	public RCFocusListener focuslistener;
	public RCMouseWheelListener wheelListener;
	public static boolean syncLEDFlag = false;
	private USBKeyboardRep keyRep;
	private USBMouseRep mouseRep;
	byte m_USBMouseMode = USBMouseRep.INVALID_MOUSE_MODE;
	private boolean initMouseMode = true;

	public static final int NUMLOCK = 1;

	public static final int CAPSLOCK = 2;
	public static final int SCROLLLOCK = 4;
	private int lastX = -1;
	private int lastY = -1;
	public Robot robbie;
	private int curX = 0;
	private int curY = 0;
	private boolean leftCtrlDown = false;
	private boolean rightCtrlDown = false;
	private boolean isMouseRedirRun = false;
	private short keyPressedFlag = 0;
	private BufferedImage localImage = new BufferedImage(1600, 1200, 1);
	private BufferedImage invisCursorImg = null;
	private Cursor cursor = null;

	public MouseEvent mouseEvent;
	public MouseEvent sendMouseEvent;
	public Thread mouse_thread;
	private Timer m_mouseTmr;
	private byte[] bdata;
	private int keyCode;
	private int keyLocation;
	private double scaleX = 1.0D;
	private double scaleY = 1.0D;
	private boolean mouseCursorOut = false;
	private boolean isCtrlPressed = false;
	private int ctrlKeyLocation;

	public JViewerView(int paramInt1, int paramInt2) {
		if ((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp())) {
			this.keyRep = new USBKeyboardRep();
			this.mouseRep = new USBMouseRep();
			this.mouseListener = new RCMouseListener();
			this.keyListener = new RCKeyListener();
			this.focuslistener = new RCFocusListener();
			this.wheelListener = new RCMouseWheelListener();
			setFocusable(true);
			setFocusTraversalKeysEnabled(false);
			addFocusListener(new RCFocusListener());
			addMouseWheelListener(new RCMouseWheelListener());
			// 鼠标跟随任务
			this.m_mouseTmr = new Timer();
			this.m_mouseTmr.schedule(new MousesendTask(), 0L, 60L);
		}
	}

	public void addKMListeners() {
		if (JViewerApp.getInstance().getHidInitDialog() != null)
			return;
		addKeyListener();
		addMouseListeners();
	}

	public void addKeyListener() {
		if (JViewerApp.getInstance().getHidInitDialog() != null)
			return;
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
			return;
		KeyListener[] arrayOfKeyListener = getKeyListeners();

		if (arrayOfKeyListener.length == 0) {
			setkeyprocessor();
			addKeyListener(this.keyListener);
		}
	}

	public void setkeyprocessor() {
		KeyProcessor localKeyProcessor = JViewerApp.getInstance().getKeyProcesssor();
		JViewerApp.getInstance().getKeyProcesssor().setAutoKeybreakMode(true);
		this.keyRep.setM_USBKeyProcessor(localKeyProcessor);
	}

	public void removeKeyListener() {
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
			return;
		removeKeyListener(this.keyListener);
	}

	public void flushHID() {
		KeyEvent localKeyEvent = new KeyEvent(this, 401, new Date().getTime(), 130, 17, '0');
		this.keyListener.keyPressed(localKeyEvent);
		localKeyEvent = new KeyEvent(this, 401, new Date().getTime(), 0, 17, '0');
		this.keyListener.keyReleased(localKeyEvent);
	}

	public void removeKMListener() {
		removeKeyListener(this.keyListener);
		removeMouseListeners();
	}

	public void addMouseListeners() {
		if (JViewerApp.getInstance().getHidInitDialog() != null)
			return;
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
			return;
		MouseListener[] arrayOfMouseListener = getMouseListeners();
		MouseMotionListener[] arrayOfMouseMotionListener = getMouseMotionListeners();

		if (arrayOfMouseListener.length == 0) {
			addMouseListener(this.mouseListener);
		}
		if (arrayOfMouseMotionListener.length == 0) {
			addMouseMotionListener(this.mouseListener);
		}
	}

	public void removeMouseListeners() {
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
			return;
		removeMouseListener(this.mouseListener);
		removeMouseMotionListener(this.mouseListener);
	}

	public int viewWidth() {
		return this.m_width;
	}

	public int viewHeight() {
		return this.m_height;
	}

	/**
	 * FIXME tianlin 设置图片
	 * 
	 * @param paramInt1
	 * @param paramInt2
	 * @param paramInt3
	 */
	public void setRCView(int paramInt1, int paramInt2, int paramInt3) {
		this.m_width = paramInt1;
		this.m_act_width = JViewerApp.getInstance().getSocframeHdr().getwidth();
		this.m_act_height = (this.m_height = paramInt2);
		this.currentWidth = JViewerApp.getInstance().getSocframeHdr().getcurwidth();
		this.currentHeight = JViewerApp.getInstance().getSocframeHdr().getcurheight();
		Debug.out.println("View - width: " + this.m_width + " height: " + this.m_height);
		// MARK by tianlin for debug, 真实数据放开
		setSize(paramInt1, paramInt2); 
		setPreferredSize(new Dimension(paramInt1, paramInt2));
		setMaximumSize(new Dimension(paramInt1, paramInt2));
		JViewerApp.getInstance().getPrepare_buf().prepareBufImage(paramInt1, paramInt2, paramInt3);
	}

	public short getM_cur_width() {
		return this.currentWidth;
	}

	public void setM_cur_width(int paramInt) {
		this.currentWidth = ((short) paramInt);
	}

	public short getM_cur_height() {
		return this.currentHeight;
	}

	public void setM_cur_height(int paramInt) {
		this.currentHeight = ((short) paramInt);
	}

	@Override
	public void update(Graphics paramGraphics) {
		paint(paramGraphics);
	}

	@Override
	public Dimension getPreferredSize() {
		BufferedImage localBufferedImage = JViewerApp.getInstance().getPrepare_buf().getM_image();
		if (localBufferedImage != null) {
			return new Dimension(
					(int) (localBufferedImage.getWidth(this)
							+ localBufferedImage.getWidth(this) * (this.scaleX - 1.0D)),
					(int) (localBufferedImage.getHeight(this)
							+ localBufferedImage.getHeight(this) * (this.scaleY - 1.0D)));
		}
		return new Dimension(1024, 768);
	}

	/**
	 * FIXME tianlin 绘制图像
	 */
	@Override
	public void paint(Graphics graphics) {
		try {
			BufferedImage preImage = JViewerApp.getInstance().getPrepare_buf().getM_image();
			if (preImage == null)
				return;
			this.localImage = preImage;
			super.paintComponent(graphics);
			Graphics2D graphics2d = (Graphics2D) graphics;
			if (preImage.getType() == BufferedImage.TYPE_USHORT_565_RGB) {
				graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
						RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
			} else {
				graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
						RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			}
			graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
			graphics2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
			graphics2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
			graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
					RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
			graphics2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
					RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
			graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
			graphics2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
			graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
			AffineTransform transform = null;
			Dimension localDimension1 = JViewerApp.getInstance().getCurrentMonitorResolution();
			Dimension localDimension2 = JViewerApp.getInstance().getMainWindow().m_viewSP.getSize();
			if ((this.m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE)
					|| (JViewerApp.getInstance().getZoomOption() == "FitToClientResolution")) {
				this.scaleX = 1.0D;
				this.scaleY = 1.0D;
				if ((preImage.getWidth() >= localDimension2.width) || (preImage.getWidth() >= localDimension1.width)) {
					this.scaleX = (localDimension2.width / preImage.getWidth());
				}
				if ((preImage.getHeight() >= localDimension2.height)
						|| (preImage.getHeight() >= localDimension1.height)) {
					this.scaleY = (localDimension2.height / preImage.getHeight());
				}
			}
			transform = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
			if (JViewer.isdownloadapp()) {
				return;
			}
			graphics2d.drawImage(preImage, transform, this);
			if (this.m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE) {
				JViewerApp.getInstance();
				if ((JViewerApp.showCursor) && (Mouse_X <= this.m_width) && (Mouse_Y <= this.m_height)) {
					URL url = JViewer.class.getResource("res/cursor.gif");
					BufferedImage bufferedImg = null;
					try {
						bufferedImg = ImageIO.read(url);
					} catch (IOException e) {
						Debug.out.println(e);
					}
					graphics.drawImage(bufferedImg, Mouse_X, Mouse_Y, null);
				}
			}
		} catch (Exception e) {
			Debug.out.println(e);
		}
	}

	public void ShowCursor(boolean paramBoolean) {
		if (this.m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE) {
			Mouse_X = 0;
			Mouse_Y = 0;
			if (this.robbie == null) {
				try {
					this.robbie = new Robot();

				} catch (AWTException localAWTException1) {
					this.robbie = null;
					return;
				}
			}
			Mousecaliberation.resetCursor();
			if (this.invisCursorImg == null) {
				this.invisCursorImg = createInvisibleCursor();
			}
			if (this.cursor == null) {
				this.cursor = Toolkit.getDefaultToolkit().createCustomCursor(this.invisCursorImg,
						new Point(0, 0), "Invisible Cursor");
			}

			setCursor(this.cursor);
			return;
		}
		if (this.m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE) {
			if (paramBoolean) {
				if (this.robbie == null) {
					try {
						this.robbie = new Robot();
					} catch (AWTException localAWTException2) {
						Debug.out.println(localAWTException2);

						this.robbie = null;
						return;
					}
				}
				JVStatusBar.OTHER_MOUISE_MODE_MSG = LocaleStrings.getString("E_1_JVIEW")
						+ LocaleStrings.getString("E_7_JVIEW") + LocaleStrings.getString("E_2_JVIEW");

				JViewerApp.getInstance().getM_wndFrame().getM_status().resetStatus();
				if (this.invisCursorImg == null)
					this.invisCursorImg = createInvisibleCursor();
				if (this.cursor == null) {
					this.cursor = Toolkit.getDefaultToolkit().createCustomCursor(this.invisCursorImg,
							new Point(0, 0), "Invisible Cursor");
				}
				setCursor(this.cursor);
			} else {
				setCursor(null);
				JVStatusBar.OTHER_MOUISE_MODE_MSG = LocaleStrings.getString("E_1_JVIEW")
						+ LocaleStrings.getString("E_7_JVIEW") + LocaleStrings.getString("E_3_JVIEW");

				JViewerApp.getInstance().getM_wndFrame().getM_status().resetStatus();
			}
			return;
		}

		if (paramBoolean) {
			if (this.m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE) {
				Mousecaliberation.resetCursor();
			} else {
				setCursor(null);
			}
		} else {
			if (this.invisCursorImg == null)
				this.invisCursorImg = createInvisibleCursor();
			if (this.cursor == null) {
				this.cursor = Toolkit.getDefaultToolkit().createCustomCursor(this.invisCursorImg,
						new Point(0, 0), "Invisible Cursor");
			}
			setCursor(this.cursor);
		}
	}

	public void SetUSBMouseMode(byte paramByte) {
		if (this.initMouseMode) {
			this.initMouseMode = false;
		} else {
			InfoDialog.showDialog(JViewer.getMainFrame(), LocaleStrings.getString("E_6_JVIEW"), 5000L);
		}

		this.m_USBMouseMode = paramByte;
		JVMenu.m_mouseMode = paramByte;
	}

	public byte GetUSBMouseMode() {
		return this.m_USBMouseMode;
	}

	public BufferedImage getImage() {
		return this.localImage;
	}

	public void mouse_resync_linux_mode(int paramInt1, int paramInt2) {
		if (Lost_focus_flag)
			return;
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG)) {
			this.mouseListener.splitandsend(-this.m_width, -this.m_height, true);
		} else {
			this.mouseListener.splitandsend_Move(-this.m_width, -this.m_height, true);
		}
		Mouse_X = 0;
		Mouse_Y = 0;

		Point localPoint = MouseInfo.getPointerInfo().getLocation();
		SwingUtilities.convertPointFromScreen(localPoint, this);
		this.lastX = ((int) localPoint.getX());
		this.lastY = ((int) localPoint.getY());
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG)) {
			this.mouseListener.splitandsend(this.lastX, this.lastY, true);
		} else {
			this.mouseListener.splitandsend_Move(this.lastX, this.lastY, true);
		}
	}

	public boolean USBsyncCursor(boolean paramBoolean) {
		if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
			return false;
		if (paramBoolean) {

			if (this.isMouseRedirRun == true) {
				return true;
			}

			if (this.m_USBMouseMode == USBMouseRep.INVALID_MOUSE_MODE) {
				JViewerApp.getInstance().getMainWindow().generalErrorMessage(LocaleStrings.getString("E_4_JVIEW"),
						LocaleStrings.getString("E_5_JVIEW"));

				return false;
			}

			addMouseListeners();
			this.isMouseRedirRun = true;
		} else {
			removeMouseListeners();
			this.isMouseRedirRun = false;
		}
		return true;
	}

	public boolean getMouseRedirStatus() {
		return this.isMouseRedirRun;
	}

	class RCKeyListener extends KeyAdapter {
		RCKeyListener() {
		}

		public void keyTyped(KeyEvent paramKeyEvent) {
			keyRep.setKeyChar(paramKeyEvent.getKeyChar());
		}

		public void keyPressed(KeyEvent paramKeyEvent) {
			byte b1 = USBKeyProcessorEnglish.getModifiers();
			// LED键处理
			// 20：大写锁定；144：数字键盘开关；145：滑动开关
			if ((paramKeyEvent.getKeyCode() == 20) || (paramKeyEvent.getKeyCode() == 144) 
					|| (paramKeyEvent.getKeyCode() == 145)) {
				if (JViewerApp.getInstance().getPowerStatus() == 0) {
					paramKeyEvent.consume();
					JViewerApp.getInstance().resetLEDStatus();
					return;
				}
			}
			
			if ((JViewerApp.getInstance().isWindowsClient()) && (paramKeyEvent.getKeyCode() != 65406)
					&& (paramKeyEvent.getModifiers() == 32)) {
				paramKeyEvent.consume();
				return;
			}
			if (((b1 & 0x1) == 1) && ((paramKeyEvent.getModifiersEx() & 0x80) != 128) && (!JViewerApp.getInstance()
					.getJVMenu().getMenuSelected("KeyboardHoldLeftCtrlKey").booleanValue())) {
				b1 = (byte) (b1 & 0xFFFFFFFE);
			}
			if (((b1 & 0x10) == 16) && ((paramKeyEvent.getModifiersEx() & 0x80) != 128) && (!JViewerApp.getInstance()
					.getJVMenu().getMenuSelected("KeyboardHoldRightCtrlKey").booleanValue())) {
				b1 = (byte) (b1 & 0xFFFFFFEF);
			}
			if (((b1 & 0x4) == 4) && ((paramKeyEvent.getModifiersEx() & 0x200) != 512) && (!JViewerApp.getInstance()
					.getJVMenu().getMenuSelected("KeyboardHoldLeftAltKey").booleanValue())) {
				b1 = (byte) (b1 & 0xFFFFFFFB);
			}
			if (((b1 & 0x40) == 64) && ((paramKeyEvent.getModifiersEx() & 0x200) != 512) && (!JViewerApp.getInstance()
					.getJVMenu().getMenuSelected("KeyboardHoldRightAltKey").booleanValue())) {

				b1 = (byte) (b1 & 0xFFFFFFBF);
			}
			if (((b1 & 0x2) == 2) && ((paramKeyEvent.getModifiersEx() & 0x40) != 64)) {
				b1 = (byte) (b1 & 0xFFFFFFFD);
			}
			if (((b1 & 0x20) == 32) && ((paramKeyEvent.getModifiersEx() & 0x40) != 64)) {
				b1 = (byte) (b1 & 0xFFFFFFDF);
			}
			USBKeyProcessorEnglish.setModifiers(b1);
			try {
				Class localClass = Class.forName("java.awt.AWTEvent");
				Field localField = localClass.getDeclaredField("bdata");
				localField.setAccessible(true);
				bdata = ((byte[]) localField.get(paramKeyEvent));
			} catch (Exception localException) {
				Debug.out.println(localException);
			}

			keyCode = paramKeyEvent.getKeyCode();
			keyLocation = paramKeyEvent.getKeyLocation();
			// JViewerView.access$408(JViewerView.this); //TODO tianlin access
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
			byte b2 = 0;

			if (paramKeyEvent.getKeyCode() == 524)
				return;
			if ((paramKeyEvent.getModifiersEx() & 0x200) == 512) {

				if ((JViewerApp.getInstance().isWindowsClient()) && ((paramKeyEvent.getModifiersEx() & 0x80) != 128)) {
					if (!JViewerApp.getInstance().isFullKeyboardEnabled()) {
						if (JViewerApp.getInstance().isFullScreenMode()) {

							OnInvokeMenuShortCutFullscreen(paramKeyEvent);
							paramKeyEvent.consume();

						}

					}

				} else if (!JViewerApp.getInstance().isFullKeyboardEnabled()) {
					if (JViewerApp.getInstance().isFullScreenMode()) {

						OnInvokeMenuShortCutFullscreen(paramKeyEvent);
						paramKeyEvent.consume();
					}

					return;
				}
			}

			if ((JViewerApp.getInstance().isLinuxClient()) && (paramKeyEvent.getKeyCode() == 65406)) {
				keyRep.set(18, 3, true);
				localKVMClient.sendKMMessage(keyRep);
				return;
			}

			if ((JViewerApp.getInstance().isWindowsClient())
					&& (JViewerApp.getInstance().getJVMenu().getMenuItem("Linux host").isSelected())) {
				if ((!isCtrlPressed()) && (paramKeyEvent.getKeyCode() == 17)) {
					setCtrlKeyLocation(paramKeyEvent.getKeyLocation());
					setCtrlPressed(true);
					return;
				}

				if ((isCtrlPressed() == true) && ((paramKeyEvent.getModifiersEx() & 0x200) == 512)) {
					keyRep.setKeyChar(paramKeyEvent.getKeyChar());
					keyRep.set(keyCode, keyLocation, true);
					localKVMClient.sendKMMessage(keyRep);
					return;
				}

				if (isCtrlPressed() == true) {

					keyRep.set(17, getCtrlKeyLocation(), true);
					localKVMClient.sendKMMessage(keyRep);
				}

				keyRep.setKeyChar(paramKeyEvent.getKeyChar());
				keyRep.set(keyCode, keyLocation, true);
			}

			if (((paramKeyEvent.getModifiersEx() & 0x200) == 512) && (paramKeyEvent.getKeyCode() == 67)
					&& (m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE)
					&& (JViewerApp.getInstance().isFullKeyboardEnabled())) {

				boolean bool = JViewerApp.getInstance().getJVMenu().getMenuSelected("MouseShowCursor").booleanValue();
				JViewerApp.getInstance().OnShowCursor(!bool);
				paramKeyEvent.consume();
				return;
			}

			if (((paramKeyEvent.getModifiersEx() & 0x80) == 128) && ((paramKeyEvent.getModifiersEx() & 0x40) == 64)) {
				if (paramKeyEvent.getKeyCode() == 76) {
					if (Debug.MODE != 0) {
						Debug.out.initDebugLogFileChooser();

					} else if (Debug.out.isRunTimeLogging()) {
						Debug.MODE = 2;
						Debug.out.closeLog();
					}

					paramKeyEvent.consume();
					return;
				}
			}

			if ((paramKeyEvent.getModifiersEx() & 0x80) == 128) {
				if (paramKeyEvent.getKeyLocation() == 2) {
					leftCtrlDown = true;
				} else
					rightCtrlDown = true;
				if ((paramKeyEvent.getKeyCode() == 112) && (!JViewerApp.getInstance().isFullKeyboardEnabled())) {
					JViewerApp.getInstance().OnHelpAboutJViewer();
					paramKeyEvent.consume();
					return;
				}
			}

			if (paramKeyEvent.getKeyCode() == 127) {
				JVMenu localJVMenu = JViewerApp.getInstance().getJVMenu();
				if (((localJVMenu.getMenuSelected("KeyboardHoldLeftCtrlKey").booleanValue())
						&& (localJVMenu.getMenuSelected("KeyboardHoldRightCtrlKey").booleanValue())
						&& (localJVMenu.getMenuSelected("KeyboardHoldRightAltKey").booleanValue()))
						|| ((localJVMenu.getMenuSelected("KeyboardHoldLeftCtrlKey").booleanValue())
								&& (localJVMenu.getMenuSelected("KeyboardHoldRightCtrlKey").booleanValue())
								&& (localJVMenu.getMenuSelected("KeyboardHoldLeftAltKey").booleanValue()))) {

					return;
				}
			}
			b2 = JViewerApp.getInstance().getHostKeyboardLEDStatus();
			if ((paramKeyEvent.getKeyCode() == 144) || (paramKeyEvent.getKeyCode() == 20)
					|| (paramKeyEvent.getKeyCode() == 145)) {
				if (paramKeyEvent.getKeyCode() == 144) {
					b2 = (byte) (b2 ^ 0x1);
				}
				if (paramKeyEvent.getKeyCode() == 20) {
					b2 = (byte) (b2 ^ 0x2);
				}
				if (paramKeyEvent.getKeyCode() == 145) {
					b2 = (byte) (b2 ^ 0x4);
				}
				JViewerApp.getInstance().getM_wndFrame().getM_status().setKeyboardLEDStatus(b2);
				JViewerApp.getInstance().getM_fsFrame().getM_menuBar().getLedStatusBar().setLEDStatus(b2);
				JViewerApp.getInstance().setHostKeyboardLEDStatus(b2);

				if ((JViewerApp.getInstance().getAutokeylayout() != null)
						&& (JViewerApp.getInstance().getAutokeylayout().OnkeyPressed(paramKeyEvent)))
					return;
			}
			if ((bdata != null) && (bdata[14] == 115))
				keyCode = 226;
			keyRep.setKeyChar(paramKeyEvent.getKeyChar());
			if ((System.getProperty("os.name").startsWith("Mac")) && (paramKeyEvent.getKeyCode() == 20)) {
				keyRep.set(keyCode, keyLocation, false);
				localKVMClient.sendKMMessage(keyRep);
			}
			if ((System.getProperty("os.name").startsWith("Linux")) && (keyCode >= 65)
					&& (keyCode <= 90)) {
				keyRep.set(keyCode, 1, true);
				localKVMClient.sendKMMessage(keyRep);
			} else {
				keyRep.set(keyCode, keyLocation, true);
				localKVMClient.sendKMMessage(keyRep);
			}
			paramKeyEvent.consume();
		}

		private void OnInvokeMenuShortCutFullscreen(KeyEvent paramKeyEvent) {
			boolean bool;
			switch (paramKeyEvent.getKeyCode()) {
			case 70:
				JViewerApp.getInstance().OnVideoFullScreen(false);
				break;
			case 69:
				JViewerApp.getInstance().OnVideoRefreshRedirection();
				break;
			case 80:
				JViewerApp.getInstance().setM_userPause(true);
				JViewerApp.getInstance().OnVideoPauseRedirection();
				break;
			case 82:
				JViewerApp.getInstance().OnVideoResumeRedirection();
				break;
			case 84:
				if ((m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE)
						&& (JViewerApp.getInstance().GetRedirectionState() == JViewerApp.REDIR_STARTED)) {
					bool = JViewerApp.getInstance().getJVMenu().getMenuSelected("Calibrate Mouse Threshold")
							.booleanValue();
					JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("Calibrate Mouse Threshold", !bool);
					JViewerApp.getInstance().OnCalibareteMouse(!bool);
					JViewerApp.getInstance().getRCView().requestFocus();
				}
				break;

			case 67:
				bool = JViewerApp.getInstance().getJVMenu().getMenuSelected("MouseShowCursor").booleanValue();
				JViewerApp.getInstance().OnShowCursor(!bool);
				break;
			case 78:
				if (JViewerApp.getInstance().getKVMClient().getHostLockStatus() == 0) {
					if (JViewerApp.getInstance().getJVMenu().getMenuItem("VideoHostDisplayLock").isEnabled()) {
						JViewerApp.getInstance().onSendHostLock((byte) 1);
					}
				} else if ((JViewerApp.getInstance().getKVMClient().getHostLockStatus() == 1)
						&& (JViewerApp.getInstance().getJVMenu().getMenuItem("VideoHostDisplayUnlock").isEnabled())) {
					JViewerApp.getInstance().onSendHostLock((byte) 0);
				}
				break;
			case 68:
			case 71:
			case 72:
			case 73:
			case 74:
			case 75:
			case 76:
			case 77:
			case 79:
			case 81:
			case 83:
			default:
				JViewerApp.getInstance().getSoc_App().OnInvokeSocMenuShortCutFullscreen(paramKeyEvent);
			}

		}

		public void keyReleased(KeyEvent paramKeyEvent) {
			try {
				Class localClass = Class.forName("java.awt.AWTEvent");
				Field localField = localClass.getDeclaredField("bdata");
				localField.setAccessible(true);
				bdata = ((byte[]) localField.get(paramKeyEvent));
			} catch (Exception localException) {
				Debug.out.println(localException);
			}
			setCtrlPressed(false);
			keyCode = paramKeyEvent.getKeyCode();
			keyLocation = paramKeyEvent.getKeyLocation();

			if ((bdata != null) && (bdata[14] == 115))
				keyCode = 226;
			keyRep.set(keyCode, keyLocation, false);
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();

			if ((JViewerApp.getInstance().isLinuxClient()) && ((paramKeyEvent.getModifiers() & 0x20) == 32)) {
				keyRep.set(18, 3, false);
				localKVMClient.sendKMMessage(keyRep);
				return;
			}

			if ((paramKeyEvent.getModifiersEx() & 0x80) == 128) {
				if (keyLocation == 2) {
					leftCtrlDown = false;
				} else
					rightCtrlDown = false;
			}
			if ((keyCode != 16) && (keyCode != 17) && (keyCode != 18)
					&& (keyCode != 65406)) {
				if ((JViewerApp.getInstance().getAutokeylayout() != null)
						&& (JViewerApp.getInstance().getAutokeylayout().OnkeyReleased(paramKeyEvent))) {
					paramKeyEvent.consume();
					keyRep.setKeyChar('\000');
					return;
				}
			}

			if ((JViewerApp.getInstance().isWindowsClient()) && (keyCode != 65406)
					&& (paramKeyEvent.getModifiers() == 32)) {
				paramKeyEvent.consume();
				keyRep.setKeyChar('\000');
				return;
			}

			keyRep.setKeyChar(paramKeyEvent.getKeyChar());
			if ((System.getProperty("os.name").startsWith("Mac")) && (paramKeyEvent.getKeyCode() == 20)) {
				keyRep.set(keyCode, keyLocation, true);
				localKVMClient.sendKMMessage(keyRep);
			}
			keyRep.set(keyCode, keyLocation, false);
			localKVMClient.sendKMMessage(keyRep);

			if (paramKeyEvent.getKeyCode() == 154) {
				if (keyPressedFlag == 0) {
					// JViewerView.access$408(JViewerView.this);
				}
			}
			if (keyPressedFlag == 0) {
				keyRep.set(paramKeyEvent.getKeyCode(), paramKeyEvent.getKeyLocation(), true);
				localKVMClient.sendKMMessage(keyRep);
				keyRep.set(paramKeyEvent.getKeyCode(), paramKeyEvent.getKeyLocation(), false);
				localKVMClient.sendKMMessage(keyRep);
			} else {
				// JViewerView.access$410(JViewerView.this);
			}
			paramKeyEvent.consume();
			keyRep.setKeyChar('\000');
		}
	}

	public class RCMouseListener extends MouseInputAdapter {
		public static final byte MOUSE_MOVE = 0;
		public static final byte LBUTTON_DOWN = 1;
		public static final byte RBUTTON_DOWN = 2;
		public static final byte MBUTTON_DOWN = 4;

		public RCMouseListener() {
		}

		private byte m_btnStatus = 0;

		public byte getM_btnStatus() {
			return this.m_btnStatus;
		}

		public void mousePressed(MouseEvent paramMouseEvent) {
			if ((curX > currentWidth * scaleX)
					|| (curY > currentHeight * scaleY)
					|| (JViewerApp.getInstance().getPowerStatus() != 1)) {
				return;
			}
			if (m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE) {

				if (!JViewerApp.getInstance().getJVMenu().getMenuItem("MouseShowCursor").isSelected()) {
					return;
				}
			}
			requestFocus();
			curX = paramMouseEvent.getX();
			curY = paramMouseEvent.getY();
			curX = (m_USBMouseMode == USBMouseRep.ABSOLUTE_MOUSE_MODE
					? paramMouseEvent.getX() : 0);
			curY = (m_USBMouseMode == USBMouseRep.ABSOLUTE_MOUSE_MODE
					? paramMouseEvent.getY() : 0);

			if (curX < 0)
				curX = 0;
			if (curY < 0) {
				curY = 0;
			}
			switch (paramMouseEvent.getButton()) {
			case 1:
				this.m_btnStatus = ((byte) (this.m_btnStatus | 0x1));
				break;

			case 2:
				this.m_btnStatus = ((byte) (this.m_btnStatus | 0x4));
				break;

			case 3:
				this.m_btnStatus = ((byte) (this.m_btnStatus | 0x2));
				break;

			default:
				return;
			}
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
			mouseRep.set(this.m_btnStatus, curX / scaleX,
					curY / scaleY, m_USBMouseMode,
					currentWidth, currentHeight, (byte) 0);

			localKVMClient.sendKMMessage(mouseRep);
			repaint();
		}

		public void mouseReleased(MouseEvent paramMouseEvent) {
			if ((curX > currentWidth * scaleX)
					|| (curY > currentHeight * scaleY)
					|| (JViewerApp.getInstance().getPowerStatus() != 1)) {
				return;
			}
			if (m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE) {

				if (!JViewerApp.getInstance().getJVMenu().getMenuItem("MouseShowCursor").isSelected()) {
					return;
				}
			}
			curX = paramMouseEvent.getX();
			curY = paramMouseEvent.getY();

			curX = (m_USBMouseMode == USBMouseRep.ABSOLUTE_MOUSE_MODE
					? paramMouseEvent.getX() : 0);
			curY = (m_USBMouseMode == USBMouseRep.ABSOLUTE_MOUSE_MODE
					? paramMouseEvent.getY() : 0);

			if (curX < 0)
				curX = 0;
			if (curY < 0) {
				curY = 0;
			}
			switch (paramMouseEvent.getButton()) {
			case 1:
				this.m_btnStatus = ((byte) (this.m_btnStatus & 0xFFFFFFFE));
				break;

			case 2:
				this.m_btnStatus = ((byte) (this.m_btnStatus & 0xFFFFFFFB));
				break;

			case 3:
				this.m_btnStatus = ((byte) (this.m_btnStatus & 0xFFFFFFFD));
				break;

			default:
				return;
			}
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
			mouseRep.set(this.m_btnStatus, curX / scaleX,
					curY / scaleY, m_USBMouseMode,
					currentWidth, currentHeight, (byte) 0);

			localKVMClient.sendKMMessage(mouseRep);
			repaint();
		}

		public void mouseMoved(MouseEvent paramMouseEvent) {
			JViewerApp.getInstance().getRCView().setMouse_event(paramMouseEvent);
		}

		public void mouseDragged(MouseEvent paramMouseEvent) {
			JViewerApp.getInstance().getRCView().setMouse_event(paramMouseEvent);
		}

		public void mouseEntered(MouseEvent paramMouseEvent) {
			mouseCursorOut = false;
			if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
				return;
			if (JViewerApp.getInstance().getJVMenu().getMenuItem("MouseShowCursor").isSelected())
				JViewerApp.showCursor = true;
			if ((m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE)
					|| ((m_USBMouseMode == USBMouseRep.ABSOLUTE_MOUSE_MODE)
							&& (!JViewerApp.showCursor))
					|| ((m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE) && (JViewerApp.showCursor))) {

				if (invisCursorImg == null)
					invisCursorImg = createInvisibleCursor();
				if (cursor == null) {
					cursor = Toolkit.getDefaultToolkit()
							.createCustomCursor(invisCursorImg, new Point(0, 0), "Invisible Cursor");
				}
				setCursor(cursor);
			}
			if ((m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE)
					&& (!Mousecaliberation.isCursorReset())) {
				Mousecaliberation.resetCursor();
			}
		}

		public void mouseExited(MouseEvent paramMouseEvent) {
			mouseCursorOut = true;
			if (m_USBMouseMode == USBMouseRep.OTHER_MOUSE_MODE) {
				JViewerApp.getInstance();
				if (JViewerApp.showCursor) {
					Point localPoint = calculateCenter();
					if (robbie == null) {
						try {
							robbie = new Robot();
						} catch (AWTException localAWTException) {
							Debug.out.println(localAWTException);
							robbie = null;
							return;
						}
					}
					robbie.mouseMove(localPoint.x, localPoint.y);
					return;
				}
			}
			if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG)) {
				return;
			}
			if (m_USBMouseMode != USBMouseRep.OTHER_MOUSE_MODE) {
				invisCursorImg = null;
				setCursor(null);
				JViewerApp.getInstance();
				JViewerApp.showCursor = false;
				repaint();
			}
		}

		public int splitandsend_Move(int paramInt1, int paramInt2, boolean paramBoolean) {
			int i = 0;
			int j = 0;

			if ((JViewerView.Lost_focus_flag) && (mouseCursorOut))
				return 0;
			int k = splitandsend(paramInt1, paramInt2, paramBoolean);

			if ((Mousecaliberation.THRESHOLDFLAG) || (Mousecaliberation.ACCELERATION_FLAG))
				return k;
			Point localPoint1 = JViewerApp.getInstance().getMainWindow().m_viewSP.getLocationOnScreen();
			int m = localPoint1.x
					- JViewerApp.getInstance().getMainWindow().m_viewSP.getHorizontalScrollBar().getValue();
			int n = localPoint1.y - JViewerApp.getInstance().getMainWindow().m_viewSP.getVerticalScrollBar().getValue();
			Point localPoint2 = MouseInfo.getPointerInfo().getLocation();
			int i1 = localPoint1.x + JViewerApp.getInstance().getSocframeHdr().getresX();
			int i2 = localPoint1.y + JViewerApp.getInstance().getSocframeHdr().getresY();

			int i3 = localPoint2.x - (m + JViewerView.Mouse_X);
			int i4 = localPoint2.y - (n + JViewerView.Mouse_Y);

			if (robbie == null)
				try {
					robbie = new Robot();
				} catch (AWTException localAWTException) {
					Debug.out.println(localAWTException);

					robbie = null;
					return k;
				}
			Point localPoint3;
			if (((i3 <= -2) || (i3 >= 2)) && (localPoint2.x < i1)) {
				removeMouseListeners();
				robbie.mouseMove(m + JViewerView.Mouse_X, localPoint2.y);
				if (System.getProperty("os.name").startsWith("Mac"))
					robbie.delay(30);
				localPoint2 = MouseInfo.getPointerInfo().getLocation();
				localPoint3 = MouseInfo.getPointerInfo().getLocation();
				k = 1;
				lastX = (localPoint3.x - m);
				addMouseListeners();
				i = 1;
			}
			if (((i4 <= -2) || (i4 >= 2)) && (localPoint2.y < i2)) {
				removeMouseListeners();
				localPoint2 = MouseInfo.getPointerInfo().getLocation();
				robbie.mouseMove(localPoint2.x, n + JViewerView.Mouse_Y);
				if (System.getProperty("os.name").startsWith("Mac"))
					robbie.delay(30);
				localPoint3 = MouseInfo.getPointerInfo().getLocation();
				k = 1;
				lastY = (localPoint3.y - n);
				addMouseListeners();
				j = 1;
			}
			if (i == 0) {
				lastX = curX;
			}
			if (j == 0) {
				lastY = curY;
			}
			return k;
		}

		public int splitandsend(int paramInt1, int paramInt2, boolean paramBoolean) {
			if ((JViewerView.Lost_focus_flag) && (mouseCursorOut)) {
				return 0;
			}
			int i = 0;

			int j = paramInt1 >= 0 ? 1 : -1;
			int k = paramInt2 >= 0 ? 1 : -1;

			removeMouseListeners();
			paramInt1 = Math.abs(paramInt1);
			paramInt2 = Math.abs(paramInt2);

			do {
				int m = paramInt1 > 126 ? 126 : paramInt1;
				int n = paramInt2 > 126 ? 126 : paramInt2;

				paramInt1 -= m;
				paramInt2 -= n;

				if (paramBoolean) {
					sendto_linux_target(m * j, n * k);
					int i1 = m * j;
					int i2 = n * k;
					if (JViewerView.firsttime) {
						JViewerView.Mouse_X = lastX;
						JViewerView.Mouse_Y = lastY;
						JViewerView.firsttime = false;
					}

					if (ABS(i1) + ABS(i2) >= JViewerView.ACCEL_THRESHOLD) {
						float f1 = i1 * JViewerView.MOUSE_ACCELERATION;
						float f2 = i2 * JViewerView.MOUSE_ACCELERATION;

						JViewerView.RemainingX += f1 % 1.0F;
						JViewerView.RemainingY += f2 % 1.0F;
						JViewerView.Mouse_X += (int) f1;
						JViewerView.Mouse_Y += (int) f2;
						if ((ABS(JViewerView.RemainingX) >= 1.0D) && (JViewerView.Mouse_X > 0)) {
							if (JViewerView.RemainingX >= 1.0D) {
								JViewerView.Mouse_X += 1;
								JViewerView.RemainingX = (float) (JViewerView.RemainingX - 1.0D);
							} else {
								JViewerView.Mouse_X -= 1;
								JViewerView.RemainingX = (float) (JViewerView.RemainingX + 1.0D);
							}
						}

						if ((ABS(JViewerView.RemainingY) >= 1.0D) && (JViewerView.Mouse_Y > 0)) {
							if (JViewerView.RemainingY >= 1.0D) {
								JViewerView.Mouse_Y += 1;
								JViewerView.RemainingY = (float) (JViewerView.RemainingY - 1.0D);
							} else {
								JViewerView.Mouse_Y -= 1;
								JViewerView.RemainingY = (float) (JViewerView.RemainingY + 1.0D);
							}
						}
					} else {
						JViewerView.Mouse_X += i1;
						JViewerView.Mouse_Y += i2;
					}

					Point localPoint1 = JViewerApp.getInstance().getMainWindow().m_viewSP.getLocationOnScreen();

					Point localPoint2 = MouseInfo.getPointerInfo().getLocation();
					if (robbie == null) {
						try {
							robbie = new Robot();
						} catch (AWTException localAWTException) {
							Debug.out.println(localAWTException);

							robbie = null;
							return i;
						}
					}

					if (JViewerView.Mouse_X <= 0) {
						JViewerView.Mouse_X = 0;
						robbie.mouseMove(localPoint1.x, localPoint2.y);
						if (System.getProperty("os.name").startsWith("Mac")) {
							robbie.delay(30);
						}
					}
					if (JViewerView.Mouse_Y <= 0) {
						JViewerView.Mouse_Y = 0;
						robbie.mouseMove(localPoint2.x, localPoint1.y);
						if (System.getProperty("os.name").startsWith("Mac")) {
							robbie.delay(30);
						}
					}
					if (JViewerView.Mouse_X >= currentWidth) {
						JViewerView.Mouse_X = currentWidth - 1;
					}
					if (JViewerView.Mouse_Y >= currentHeight) {
						JViewerView.Mouse_Y = currentHeight - 1;
					}

					repaint();
				} else {
					KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
					mouseRep.set(this.m_btnStatus, m * j / scaleX,
							n * k / scaleY, m_USBMouseMode,
							currentWidth, currentHeight, (byte) 0);

					localKVMClient.sendKMMessage(mouseRep);
				}
			} while ((paramInt1 > 0) || (paramInt2 > 0));
			addMouseListeners();
			return i;
		}

		private int ABS(int paramInt) {
			return paramInt < 0 ? -paramInt : paramInt;
		}

		private float ABS(float paramFloat) {
			return paramFloat < 0.0F ? -paramFloat : paramFloat;
		}

		private void sendto_linux_target(int paramInt1, int paramInt2) {
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
			mouseRep.set(this.m_btnStatus, paramInt1 / scaleX,
					paramInt2 / scaleY, m_USBMouseMode, currentWidth,
					currentHeight, (byte) 0);

			localKVMClient.sendKMMessage(mouseRep);
		}
	}

	class RCFocusListener extends FocusAdapter {
		RCFocusListener() {
		}

		public void focusGained(FocusEvent paramFocusEvent) {
			JViewerView.Lost_focus_flag = false;
			if (m_USBMouseMode == USBMouseRep.RELATIVE_MOUSE_MODE) {
				Mousecaliberation.resetCursor();
			}
		}

		public void focusLost(FocusEvent paramFocusEvent) {
			JViewerView.Lost_focus_flag = true;
		}
	}

	class RCMouseWheelListener implements MouseWheelListener {
		RCMouseWheelListener() {
		}

		public void mouseWheelMoved(MouseWheelEvent paramMouseWheelEvent) {
			byte b = (byte) paramMouseWheelEvent.getWheelRotation();

			if (b < 0) {
				b = 1;
			} else {
				b = -1;
			}
			KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
			mouseRep.set((byte) 0, 0.0D, 0.0D, m_USBMouseMode,
					currentWidth, currentHeight, b);

			localKVMClient.sendKMMessage(mouseRep);
		}
	}

	public USBKeyboardRep getM_USBKeyRep() {
		return this.keyRep;
	}

	public void setM_USBKeyRep(USBKeyboardRep paramUSBKeyboardRep) {
		this.keyRep = paramUSBKeyboardRep;
	}

	public MouseEvent getMouse_event() {
		return this.mouseEvent;
	}

	public void setMouse_event(MouseEvent paramMouseEvent) {
		this.mouseEvent = paramMouseEvent;
	}

	public USBMouseRep getM_USBMouseRep() {
		return this.mouseRep;
	}

	public void setM_USBMouseRep(USBMouseRep paramUSBMouseRep) {
		this.mouseRep = paramUSBMouseRep;
	}

	class MousesendTask extends TimerTask {
		MousesendTask() {
		}

		public void run() {
			MouseEvent localMouseEvent1 = JViewerApp.getInstance().getRCView().getMouse_event();
			MouseEvent localMouseEvent2 = JViewerApp.getInstance().getRCView().getSentmouse_event();
			byte b1 = GetUSBMouseMode();
			USBMouseRep localUSBMouseRep = getM_USBMouseRep();

			byte b2 = JViewerApp.getInstance().getRCView().mouseListener.getM_btnStatus();

			if (currentWidth <= 0)
				currentWidth = JViewerApp.getInstance().getSocframeHdr().getcurwidth();
			if (currentHeight <= 0) {
				currentHeight = JViewerApp.getInstance().getSocframeHdr().getcurheight();
			}
			if ((localMouseEvent1 != null) && (localMouseEvent2 != null)) {
				long l1 = localMouseEvent2.getWhen();
				long l2 = localMouseEvent1.getWhen();
				if (l1 == l2) {
					return;
				}
			}
			if (localMouseEvent1 != null) {
				curX = localMouseEvent1.getX();
				curY = localMouseEvent1.getY();

				if (curX < 0)
					curX = 0;
				if (curY < 0) {
					curY = 0;
				}
				if (b1 == USBMouseRep.ABSOLUTE_MOUSE_MODE) {

					if ((curX < currentWidth * scaleX)
							&& (curY < currentHeight * scaleY)
							&& (JViewerApp.getInstance().getPowerStatus() == 1)) {

						KVMClient localKVMClient1 = JViewerApp.getInstance().getKVMClient();
						localUSBMouseRep.set(b2, curX / scaleX,
								curY / scaleY, b1, currentWidth,
								currentHeight, (byte) 0);

						localKVMClient1.sendKMMessage(localUSBMouseRep);
						JViewerApp.getInstance().getRCView().setSentmouse_event(localMouseEvent1);
					}
				} else {
					int i;
					int j;
					int k;
					if (b1 == USBMouseRep.RELATIVE_MOUSE_MODE) {

						i = curX - lastX;
						j = curY - lastY;
						k = 0;

						if ((curX < currentWidth * scaleX)
								&& (curY < currentHeight * scaleY)
								&& (JViewerApp.getInstance().getPowerStatus() == 1)) {

							k = JViewerApp.getInstance().getRCView().mouseListener.splitandsend_Move(i, j, true);
						}
						JViewerApp.getInstance().getRCView().setSentmouse_event(localMouseEvent1);

						if (k != 0) {
						}

					} else if (b1 == USBMouseRep.OTHER_MOUSE_MODE) {
						i = 0;
						j = 0;
						k = 0;
						int m = 0;

						if ((!JViewerApp.getInstance().getJVMenu().getMenuSelected("MouseShowCursor").booleanValue())
								|| (JViewerApp.getInstance().getPowerStatus() == 0) || (JViewerView.Lost_focus_flag)) {

							return;
						}

						if (lastX == -1) {

							Point localPoint = calculateCenter();
							SwingUtilities.convertPointToScreen(localPoint, getTopLevelAncestor());
							SwingUtilities.convertPointFromScreen(localPoint, JViewerView.this);
							lastX = localPoint.x;
							lastY = localPoint.y;
						}

						if ((lastX - curX == i)
								&& (lastY - curY == j)) {
							i = 0;
							j = 0;
							lastX = curX;
							lastY = curY;
							return;
						}

						i += curX - lastX;
						j += curY - lastY;

						lastX = curX;
						lastY = curY;

						Point localPoint = calculateCenter();

						SwingUtilities.convertPointToScreen(localPoint, JViewer.getMainFrame());

						if (robbie == null) {
							try {
								robbie = new Robot();
							} catch (AWTException localAWTException) {
								Debug.out.println(localAWTException);

								robbie = null;
								return;
							}
						}
						robbie.mouseMove(localPoint.x, localPoint.y);

						SwingUtilities.convertPointFromScreen(localPoint, JViewerView.this);

						k = localPoint.x;
						m = localPoint.y;

						if (k >= m_width) {
							k = m_width - 1;
						}

						if (m >= m_height) {
							m = m_height - 1;
						}

						int n = curX - k;
						int i1 = curY - m;

						k = curX;
						m = curY;

						int i2 = n >= 0 ? 1 : -1;
						int i3 = i1 >= 0 ? 1 : -1;

						n = Math.abs(n);
						i1 = Math.abs(i1);

						KVMClient localKVMClient2 = JViewerApp.getInstance().getKVMClient();

						do {
							int i4 = n > 126 ? 126 : n;
							int i5 = i1 > 126 ? 126 : i1;

							n -= i4;
							i1 -= i5;
							localUSBMouseRep.set(b2, i4 * i2, i5 * i3, b1, currentWidth,
									currentHeight, (byte) 0);
							localKVMClient2.sendKMMessage(localUSBMouseRep);
						} while ((n > 0) || (i1 > 0));

						JViewerApp.getInstance().getRCView().setSentmouse_event(localMouseEvent1);
					}
				}
				repaint();
			}
		}
	}

	public MouseEvent getSentmouse_event() {
		return this.sendMouseEvent;
	}

	public void setSentmouse_event(MouseEvent paramMouseEvent) {
		this.sendMouseEvent = paramMouseEvent;
	}

	private Point calculateCenter() {
		Point localPoint1 = JViewerApp.getInstance().getRCView().getLocationOnScreen();
		Point localPoint2 = new Point((this.currentWidth + localPoint1.x) / 2, (this.currentHeight + localPoint1.y) / 2);
		return localPoint2;
	}

	public void setScaleFactor(double paramDouble1, double paramDouble2) {
		this.scaleX = paramDouble1;
		this.scaleY = paramDouble2;
	}

	public double getScaleX() {
		return this.scaleX;
	}

	public void setScaleX(double paramDouble) {
		this.scaleX = paramDouble;
	}

	public double getScaleY() {
		return this.scaleY;
	}

	public void setScaleY(double paramDouble) {
		this.scaleY = paramDouble;
	}

	public boolean isMouseCursorOut() {
		return this.mouseCursorOut;
	}

	public void setMouseCursorOut(boolean paramBoolean) {
		this.mouseCursorOut = paramBoolean;
	}

	public BufferedImage createInvisibleCursor() {
		BufferedImage localBufferedImage = new BufferedImage(32, 32, 2);
		Graphics2D localGraphics2D = localBufferedImage.createGraphics();
		AlphaComposite localAlphaComposite = AlphaComposite.getInstance(1, 0.0F);
		localGraphics2D.setComposite(localAlphaComposite);
		return localBufferedImage;
	}

	public boolean isCtrlPressed() {
		return this.isCtrlPressed;
	}

	public void setCtrlPressed(boolean paramBoolean) {
		this.isCtrlPressed = paramBoolean;
	}

	public int getCtrlKeyLocation() {
		return this.ctrlKeyLocation;
	}

	public void setCtrlKeyLocation(int paramInt) {
		this.ctrlKeyLocation = paramInt;
	}
}
